package com.liyuxiang.graph.context;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 智能问诊上下文数据模型
 * 用于存储和管理问诊过程中的所有状态信息
 */
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class DiagnosisContext {
    
    private String userId;
    private String threadId;
    private String intentType;
    private Map<String, Object> symptoms;
    private List<String> conversationHistory;
    private Integer questionCount;
    private String recommendedDepartment;
    private String lastResponse;
    private Boolean isCompleted;
    private Boolean shouldContinue;
    private LocalDateTime createdAt;
    private LocalDateTime updatedAt;
    
    public DiagnosisContext() {
        this.symptoms = new HashMap<>();
        this.conversationHistory = new ArrayList<>();
        this.questionCount = 0;
        this.isCompleted = false;
        this.shouldContinue = true;
        this.createdAt = LocalDateTime.now();
        this.updatedAt = LocalDateTime.now();
    }
    
    public DiagnosisContext(String userId, String threadId) {
        this();
        this.userId = userId;
        this.threadId = threadId;
    }
    
    // 更新时间戳
    public void updateTimestamp() {
        this.updatedAt = LocalDateTime.now();
    }
    
    // 添加对话历史
    public void addConversationHistory(String message) {
        if (this.conversationHistory == null) {
            this.conversationHistory = new ArrayList<>();
        }
        this.conversationHistory.add(message);
        updateTimestamp();
    }
    
    // 添加症状信息
    public void addSymptom(String key, Object value) {
        if (this.symptoms == null) {
            this.symptoms = new HashMap<>();
        }
        this.symptoms.put(key, value);
        updateTimestamp();
    }
    
    // 增加问题计数
    public void incrementQuestionCount() {
        this.questionCount = (this.questionCount == null ? 0 : this.questionCount) + 1;
        updateTimestamp();
    }
    
    // Getters and Setters
    public String getUserId() {
        return userId;
    }
    
    public void setUserId(String userId) {
        this.userId = userId;
    }
    
    public String getThreadId() {
        return threadId;
    }
    
    public void setThreadId(String threadId) {
        this.threadId = threadId;
    }
    
    public String getIntentType() {
        return intentType;
    }
    
    public void setIntentType(String intentType) {
        this.intentType = intentType;
        updateTimestamp();
    }
    
    public Map<String, Object> getSymptoms() {
        return symptoms;
    }
    
    public void setSymptoms(Map<String, Object> symptoms) {
        this.symptoms = symptoms;
        updateTimestamp();
    }
    
    public List<String> getConversationHistory() {
        return conversationHistory;
    }
    
    public void setConversationHistory(List<String> conversationHistory) {
        this.conversationHistory = conversationHistory;
        updateTimestamp();
    }
    
    public Integer getQuestionCount() {
        return questionCount;
    }
    
    public void setQuestionCount(Integer questionCount) {
        this.questionCount = questionCount;
        updateTimestamp();
    }
    
    public String getRecommendedDepartment() {
        return recommendedDepartment;
    }
    
    public void setRecommendedDepartment(String recommendedDepartment) {
        this.recommendedDepartment = recommendedDepartment;
        updateTimestamp();
    }
    
    public String getLastResponse() {
        return lastResponse;
    }
    
    public void setLastResponse(String lastResponse) {
        this.lastResponse = lastResponse;
        updateTimestamp();
    }
    
    public Boolean getIsCompleted() {
        return isCompleted;
    }
    
    public void setIsCompleted(Boolean isCompleted) {
        this.isCompleted = isCompleted;
        updateTimestamp();
    }
    
    public Boolean getShouldContinue() {
        return shouldContinue;
    }
    
    public void setShouldContinue(Boolean shouldContinue) {
        this.shouldContinue = shouldContinue;
        updateTimestamp();
    }
    
    public LocalDateTime getCreatedAt() {
        return createdAt;
    }
    
    public void setCreatedAt(LocalDateTime createdAt) {
        this.createdAt = createdAt;
    }
    
    public LocalDateTime getUpdatedAt() {
        return updatedAt;
    }
    
    public void setUpdatedAt(LocalDateTime updatedAt) {
        this.updatedAt = updatedAt;
    }
    
    @Override
    public String toString() {
        return "DiagnosisContext{" +
                "userId='" + userId + '\'' +
                ", threadId='" + threadId + '\'' +
                ", intentType='" + intentType + '\'' +
                ", questionCount=" + questionCount +
                ", isCompleted=" + isCompleted +
                ", shouldContinue=" + shouldContinue +
                ", symptomsCount=" + (symptoms != null ? symptoms.size() : 0) +
                ", conversationCount=" + (conversationHistory != null ? conversationHistory.size() : 0) +
                '}';
    }
}